﻿using System.Configuration;
using Microsoft.WindowsAzure;

namespace XamlingCore.AzureHelper
{
    internal static class AzureCommon
    {
        public static CloudStorageAccount GetStorageAccount()
        {
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                // for a console app, reading from App.config
                //configSetter(ConfigurationManager.AppSettings[configName]);
                // OR, if running in the Windows Azure environment
                // configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                configSetter(ConfigurationManager.AppSettings[configName]);
            });

            var result = CloudStorageAccount.FromConfigurationSetting("storage_account");
            return result;

            //return CloudStorageAccount.DevelopmentStorageAccount;

            //if (!Debugger.IsAttached)
            //{
            //    //StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(
            //    //    (String)ConfigurationSettings.AppSettings["AccountName"],
            //    //    (String)ConfigurationSettings.AppSettings["AccountSharedKey"]
            //    //);
            //    //CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(storageCredentialsAccountAndKey, true);
            //    //return cloudStorageAccount; 

                
            //}
            //else
            //{
            //    return CloudStorageAccount.DevelopmentStorageAccount;
            //}
        }
    }
}
